
package com.tanker.common.utils.microRental;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.tanker.common.utils.microRental.common.ConfUtil;
import com.tanker.common.utils.microRental.common.HttpBlockPostSender;
import com.tanker.common.utils.microRental.common.HttpSender;
import com.tanker.common.utils.microRental.common.SignHelp;



public class APIClient {
	private final Logger logger = LoggerFactory.getLogger(APIClient.class);
	
	public String post(Map<String, String> parameter, String uri) {
		Map<String, String> postParameter = new HashMap<String, String>();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		//date.setTime(date.getTime());
		date.setTime(date.getTime()-3*60*1000);

		postParameter.putAll(parameter);
		postParameter.put("uid", ConfUtil.uid);
		postParameter.put("reqTime", dateFormat.format(date));

		String sign = SignHelp.generateSign(postParameter, uri, ConfUtil.privateKey);
		postParameter.put(ConfUtil.SIGN, sign);

		HttpSender sender = new HttpBlockPostSender();
		String result = sender.send(postParameter, ConfUtil.bathPath + uri);
		logger.info("original return result: " + result);

		return result;
	}

}
